﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using OpenTK.Graphics.OpenGL;
using System.Drawing;

namespace DataModel.Shapes
{
    public class Pyramid : SimpleShape
    {

        public Pyramid(float width, float height, float depth, System.Drawing.Color color, float x, float y, float z) :
            base(height, width, depth, color, x, y, z)
        {
            this.Vertices = new List<Point3D>();

            UpdateVertices(x, y, z);
        }
        
        public override void DrawShape()
        {            
            GL.Begin(BeginMode.Quads);
                        
            GL.Color3(base.ColorBottom);

            //bottom            
            GL.Vertex3(this.Vertices[1].X, this.Vertices[1].Y, this.Vertices[1].Z);
            GL.Vertex3(this.Vertices[2].X, this.Vertices[2].Y, this.Vertices[2].Z);
            GL.Vertex3(this.Vertices[3].X, this.Vertices[3].Y, this.Vertices[3].Z);
            GL.Vertex3(this.Vertices[4].X, this.Vertices[4].Y, this.Vertices[4].Z);

            GL.End();

            GL.Begin(BeginMode.Triangles);
            
            GL.Color3(base.Color);

            //front wall
            GL.Vertex3(this.Vertices[0].X, this.Vertices[0].Y, this.Vertices[0].Z);
            GL.Vertex3(this.Vertices[3].X, this.Vertices[3].Y, this.Vertices[3].Z);
            GL.Vertex3(this.Vertices[4].X, this.Vertices[4].Y, this.Vertices[4].Z);

            //right side
            GL.Vertex3(this.Vertices[0].X, this.Vertices[0].Y, this.Vertices[0].Z);
            GL.Vertex3(this.Vertices[2].X, this.Vertices[2].Y, this.Vertices[2].Z);
            GL.Vertex3(this.Vertices[3].X, this.Vertices[3].Y, this.Vertices[3].Z);
            
            //back wall
            GL.Vertex3(this.Vertices[0].X, this.Vertices[0].Y, this.Vertices[0].Z);
            GL.Vertex3(this.Vertices[2].X, this.Vertices[2].Y, this.Vertices[2].Z);
            GL.Vertex3(this.Vertices[1].X, this.Vertices[1].Y, this.Vertices[1].Z);

            //left side
            GL.Vertex3(this.Vertices[0].X, this.Vertices[0].Y, this.Vertices[0].Z);
            GL.Vertex3(this.Vertices[1].X, this.Vertices[1].Y, this.Vertices[1].Z);
            GL.Vertex3(this.Vertices[4].X, this.Vertices[4].Y, this.Vertices[4].Z);
            
            GL.End();            
        }

        public override void UpdateVertices(float x, float y, float z)
        {
            this.X = x;
            this.Y = y;
            this.Z = z;

            if (this.Vertices == null)
                return;

            this.Vertices.Clear();

            //top
            this.Vertices.Add(new Point3D(x, ((Height / 2) + y), z));

            //bottom - LB, RB, RF, LF
            this.Vertices.Add(new Point3D((-Width/2) + x, (-Height /2) + y, (- Depth/2) + z));
            this.Vertices.Add(new Point3D((Width/2) + x, (-Height /2) + y, (- Depth/2) + z));
            this.Vertices.Add(new Point3D((Width/2) + x, (-Height /2) + y, (Depth/2) + z));
            this.Vertices.Add(new Point3D((-Width/2) + x, (-Height /2) + y, (Depth/2) + z));
        }
    }
}
